{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* joblib多线程示例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=5)]: Using backend LokyBackend with 5 concurrent workers.\n",
      "[Parallel(n_jobs=5)]: Done   2 out of   5 | elapsed:    5.4s remaining:    8.1s\n",
      "[Parallel(n_jobs=5)]: Done   5 out of   5 | elapsed:    5.4s finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[('2019-11-08 19:30:31', '2019-11-08 19:30:36'),\n",
       " ('2019-11-08 19:30:31', '2019-11-08 19:30:36'),\n",
       " ('2019-11-08 19:30:31', '2019-11-08 19:30:36'),\n",
       " ('2019-11-08 19:30:31', '2019-11-08 19:30:36'),\n",
       " ('2019-11-08 19:30:31', '2019-11-08 19:30:36')]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from joblib import Parallel, delayed\n",
    "import numpy as np\n",
    "import time\n",
    "import datetime\n",
    "\n",
    "def job(i):\n",
    "    start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')\n",
    "    time.sleep(5)\n",
    "    end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')\n",
    "    \n",
    "    return start, end\n",
    "\n",
    "result = Parallel(n_jobs=5, verbose=1)(delayed(job)(j) for j in range(5))\n",
    "result"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
